const Router=require('koa-router');
const author=new Router(); 
const sqldata = require('../sqldata');
//获得全部诗人
author.get('/',async(ctx)=>{
    let sql=`select * from authorfoot`
    let mydata = await new Promise((resolve, reject)=>{
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=JSON.parse(JSON.stringify(mydata))
})
//增加诗人
author.post('/',async(ctx)=>{
    let val=ctx.request.body
    let sql;
    let mydata= await new Promise((resolve, reject)=>{
        sql=`insert into authorfoot (aname,aintro,adynasty,aaddress) values ('${val.aname}','${val.aintro}','${val.adynasty}','${val.aaddress}')`
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
})
//删除诗人
author.delete('/',async(ctx)=>{
    let val=ctx.request.body
    let sql=`delete from authorfoot where aid=${val.aid}`
    let mydata = await new Promise((resolve, reject)=>{
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
})
module.exports=author;